﻿using System;
using System.Reflection;

namespace WyUnity.Utility
{
	/// <summary>
	/// attribute辅助类
	/// </summary>
	public static class AttributeHelper
	{
		/// <summary>
		/// 获取唯一的Attribute，如果没有定义，返回null
		/// </summary>
		public static T GetSingleAttribute<T>(this MemberInfo memberInfo) where T : Attribute
		{
			var atts = memberInfo.GetCustomAttributes(typeof(T), false);
			if (atts.Length == 1)
			{
				return (T)atts[0];
			}
			return null;
		}
	}
}